package com.wuye.basic.service.impl;

import java.util.List;

import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuye.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wuye.basic.mapper.WyCommunityMapper;
import com.wuye.basic.domain.WyCommunity;
import com.wuye.basic.service.IWyCommunityService;

/**
 * 小区Service业务层处理
 * 
 * @author avalon
 * @date 2024-11-23
 */
@Service
public class WyCommunityServiceImpl extends ServiceImpl<WyCommunityMapper,WyCommunity>
        implements IWyCommunityService
{
    @Autowired
    private WyCommunityMapper wyCommunityMapper;

    /**
     * 查询小区
     * 
     * @param communityId 小区主键
     * @return 小区
     */
    @Override
    public WyCommunity selectWyCommunityByCommunityId(Long communityId)
    {
        return wyCommunityMapper.selectWyCommunityByCommunityId(communityId);
    }

    /**
     * 查询小区列表
     * 
     * @param wyCommunity 小区
     * @return 小区
     */
    @Override
    public List<WyCommunity> selectWyCommunityList(WyCommunity wyCommunity)
    {
        return wyCommunityMapper.selectWyCommunityList(wyCommunity);
    }

    /**
     * 新增小区
     * 
     * @param wyCommunity 小区
     * @return 结果
     */
    @Override
    public int insertWyCommunity(WyCommunity wyCommunity)
    {
        wyCommunity.setCreateTime(DateUtils.getNowDate());
        return wyCommunityMapper.insertWyCommunity(wyCommunity);
    }

    /**
     * 修改小区
     * 
     * @param wyCommunity 小区
     * @return 结果
     */
    @Override
    public int updateWyCommunity(WyCommunity wyCommunity)
    {
        return wyCommunityMapper.updateWyCommunity(wyCommunity);
    }

    /**
     * 批量删除小区
     * 
     * @param communityIds 需要删除的小区主键
     * @return 结果
     */
    @Override
    public int deleteWyCommunityByCommunityIds(Long[] communityIds)
    {
        return wyCommunityMapper.deleteWyCommunityByCommunityIds(communityIds);
    }

    /**
     * 删除小区信息
     * 
     * @param communityId 小区主键
     * @return 结果
     */
    @Override
    public int deleteWyCommunityByCommunityId(Long communityId)
    {
        return wyCommunityMapper.deleteWyCommunityByCommunityId(communityId);
    }

    @Override
    public List<WyCommunity> listByInfo(WyCommunity wyCommunity) {
        return lambdaQuery()
                .like(CharSequenceUtil.isNotBlank(wyCommunity.getCommunityName()),WyCommunity::getCommunityName,wyCommunity.getCommunityName())
                .eq(CharSequenceUtil.isNotBlank(wyCommunity.getCommunityPhone()),WyCommunity::getCommunityPhone,wyCommunity.getCommunityPhone())
                .eq(wyCommunity.getCommunityMoney() != null , WyCommunity::getCommunityMoney,wyCommunity.getCommunityMoney())
                .eq(wyCommunity.getCommunityManageId() != null , WyCommunity::getCommunityManageId,wyCommunity.getCommunityManageId())
                .list();
    }

    @Override
    public List<WyCommunity> listToName() {
        return lambdaQuery().select(WyCommunity::getCommunityId,WyCommunity::getCommunityName).list();
    }
}
